package week4.day23;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

/**
 * 从磁盘上读取一个文本文件（推荐找一个Java源代码文件）分别统计出文件中英文字母、空格、数字字符的个数。在控制台打印出结果即可。
 * 注：判断是xx字符，可以考虑用包装类型Character，也可以直接简单粗暴的用char类型来进行判断。
 * @Author fengzihao
 * @Date 2024-05-07 20:31
 */
public class Count {
    public static void main(String[] args) throws IOException {
        File sourceFile = new File("src\\week4\\day23\\ReadAndeSortAndWriter.java");
        FileInputStream fileInputStream = new FileInputStream(sourceFile);
        int englishCount = 0;
        int numCount = 0;
        int spaceCount = 0;
        int readNum = -1;
        while ((readNum = fileInputStream.read())!=-1){
            if (Character.isLetter(readNum))
                englishCount++;
            if (Character.isDigit(readNum))
                numCount++;
            if (Character.isSpaceChar(readNum))
                spaceCount++;
        }
        System.out.println("englishCount = " + englishCount);
        System.out.println("numCount = " + numCount);
        System.out.println("spaceCount = " + spaceCount);
    }
}
